import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_localizations/flutter_localizations.dart';
import 'package:share_fit/app/controllers/theme/ThemesController.dart';
import 'package:share_fit/app/helper/db/ute_db_helper.dart';
import 'package:share_fit/app/helper/storage_helper.dart';
import 'package:share_fit/app/routes/routes.dart';
import 'package:share_fit/app/tools/app_util.dart';
import 'package:share_fit/app/tools/locale_tool.dart';
import 'package:share_fit/app/tools/color_const.dart';
import 'package:share_fit/app/ute/uteped_helper.dart';
import 'package:share_fit/app/ute/uteped_sports.dart';
import 'package:share_fit/generated/locales.g.dart';
import 'package:get/get.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';

Future<void> main() async {
  WidgetsFlutterBinding.ensureInitialized();
  await StorageHelper.init();
  await LocaleTool.init();
  // AppUtil.requestPermissions();
  UTEPedHelper.init();
  UteDbHelper.init();
  UTEPedSports();
  runApp(MyApp());
}

class MyApp extends StatelessWidget {
  MyApp({super.key});

  final ThemesController themeController = Get.put(ThemesController());
  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    SystemChrome.setPreferredOrientations([
          DeviceOrientation.portraitUp,
          DeviceOrientation.portraitDown
        ]);
    MediaQueryData queryData = MediaQuery.of(context);
    if (kDebugMode) {
      print("width: ${queryData.size.width} and height: ${queryData.size.height}");
    }
    List<String> launch = LocaleTool.configLaunch();

    return ScreenUtilInit(
      designSize: const Size(1125, 2436),
      minTextAdapt: true,
      splitScreenMode: true,
      builder: (context , child) {
        return GetMaterialApp(
          title: '3+ GO',
          getPages: Routes.getPages(),
          navigatorObservers: [Routes.navigationHistoryObserver],
          initialRoute: Routes.INITIAL,
          translationsKeys: AppTranslation.translations,
          locale: Locale(launch[0], launch[1]),
          fallbackLocale: const Locale("en", "US"),
          debugShowCheckedModeBanner: false,
          builder: (context, child) => MediaQuery(
            data: MediaQuery.of(context).copyWith(boldText: false, textScaler: TextScaler.noScaling),
            child: child!,
          ),
          defaultTransition: Transition.circularReveal,
          // useInheritedMediaQuery: false,
          localeResolutionCallback: (Locale? locale, Iterable<Locale> supportedLocales) {
            LocaleTool.inst.onLocalChanged(locale);
            return null;
          },
          supportedLocales: const [
            Locale('zh', 'CN'),
            Locale('en', 'US'),
          ],
          localizationsDelegates: const [
            GlobalMaterialLocalizations.delegate,
            GlobalWidgetsLocalizations.delegate,
            GlobalCupertinoLocalizations.delegate, // iOS
          ],
          theme: ThemeData(
            splashColor: ColorConst.activeColor,
            highlightColor: ColorConst.activeColor,
            scaffoldBackgroundColor: ColorConst.mainBgColor,
            useMaterial3: true,
          ),
        );
      });
  }

}

